<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }" style="font-size: 35px">客户订单</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>

    <div>
      <el-pagination style="float: right;"
                     @current-change="changePage"
                     hide-on-single-page
                     layout="total, prev, pager, next"
                     :current-page="currentPage"
                     :page-size="pageSize"
                     :total="total">
      </el-pagination>
    </div>

    <el-table :data="orderArr">
      <el-table-column prop="serialNumber" label="订单编号" align="center" width="120"></el-table-column>
      <el-table-column prop="username" label="用户名" align="center" width="120"></el-table-column>
      <el-table-column prop="username" label="陪诊员姓名" align="center" width="120"></el-table-column>
      <el-table-column prop="productName" label="商品名字" align="center" width="120"></el-table-column>
      <el-table-column prop="price" label="价格" align="center" width="120"></el-table-column>
      <el-table-column prop="payChannel" label="支付渠道" align="center" width="120"></el-table-column>
<!--      <el-table-column prop="state" label="订单状态" align="center" width="120"></el-table-column>-->
      <el-table-column prop="state" label="订单状态" align="center" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.state === 0">待接单</span>
          <span v-if="scope.row.state === 1">订单已完成</span>
          <span v-else-if="scope.row.state === 2">已接单</span>
          <span v-else-if="scope.row.state === 3">订单已取消</span>
          <span v-else-if="scope.row.state === 4">等待同意退款</span>
        </template>
      </el-table-column>
      <el-table-column prop="gmtCreate" label="创建时间" align="center" width="170" :formatter="formatDate"></el-table-column>
      <el-table-column prop="gmtPay" label="支付时间" align="center" width="170" :formatter="formatDate"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" :disabled="scope.row.state === 0 || scope.row.state === 1 || scope.row.state===2 || scope.row.state===3|| scope.row.state===4 " @click="cancel(scope.row)">取消订单</el-button>
          <br>
          <br>
          <el-button size="mini" type="success":disabled="scope.row.state === 0 || scope.row.state === 1 || scope.row.state===3|| scope.row.state===4 " @click="accomplish(scope.row)">完成订单</el-button>
          <br>
          <br>
          <el-button size="mini" type="success" :disabled="scope.row.state === 3 ||  scope.row.state===2 || scope.row.state===1|| scope.row.state===4 " @click="reception(scope.row)">接取订单</el-button>
          <br>
          <br>
          <el-button size="mini" type="success" :disabled="scope.row.state === 3 ||  scope.row.state===2 || scope.row.state===1|| scope.row.state===4 " @click="signOrder(scope.row)">签到订单</el-button>

        </template>
      </el-table-column>
    </el-table>



  </div>
</template>

<script>
export default {
  name: "personal"
}
</script>

<script>
import TokenAxios from "@/http/TokenAxios";
import BaseUrl from "@/http/BaseUrl";

export default {
  methods: {
    changePage(page) {
      this.$router.replace('?page=' + page);
      this.orderList();
    },
    orderList(){

      let page = this.$router.currentRoute.query.page;
      if (!page) {
        page = 1;
      }

      TokenAxios.get(BaseUrl.ORDER+'/orders/staffList?page='+page).then((response)=>{
        if (response.data.state=20000){
          console.log(response.data)
          console.log(response.data.data)
          console.log(this.orderArr)
          // this.orderArr=response.data.data.list;
          this.orderArr=response.data.data.list;
          this.total = response.data.data.total;
          this.pageSize = response.data.data.pageSize;
          this.currentPage = response.data.data.currentPage;
        }
      })
    },
    formatDate(row,column){
      let data = row[column.property]
      if(data == null){
        return null
      }
      let dt = new Date(data)
      return dt.getFullYear()+'-'+(dt.getMonth()+1)+'-'+dt.getDate()+' '+dt.getHours()+':'+dt.getMinutes()+':'+dt.getSeconds()
    },
    cancel(deleteOrder){
      debugger
      console.log(deleteOrder.serialNumber)
      TokenAxios.post(BaseUrl.ORDER+'/orders/'+deleteOrder.serialNumber+'/'+3).then((response)=>{
        debugger
        if (response.data.state=20000){
          this.$message({
            message:'订单已取消',
            type:'success'
          })
          this.orderList();
        }
      })
    },
    accomplish(deleteOrder){
      debugger
      TokenAxios.post(BaseUrl.ORDER+'/orders/'+deleteOrder.serialNumber+'/'+1).then((response)=>{
        debugger
        if (response.data.state=20000){
          this.$message({
            message:'订单已完成',
            type:'success'
          })
          this.orderList();
        }
      })
    },
    reception(deleteOrder){
      debugger
      TokenAxios.post(BaseUrl.ORDER+'/orders/'+deleteOrder.serialNumber+'/'+2).then((response)=>{
        debugger
        if (response.data.state=20000){
          this.$message({
            message:'已接单',
            type:'success'
          })
          this.orderList();
        }
      })
    },
    signOrder(order){
      debugger
      this.$router.push('/signIn?id='+order.serialNumber);
    }
  },

  data() {
    return {
      orderArr:[],
      total: 0,
      pageSize: 0,
      currentPage: 0
    }
  },
  mounted(){
    this.orderList();
  }
}
</script>
